<?php 

include("config.php");
include("thumb.php");

if (!isset($_GET["id"])) {
	exit;
}

$id = htmlspecialchars($_GET["id"]);

$query="SELECT * FROM gallery where id = ".$id;
$result=mysql_query($query);

$imagedir=mysql_result($result,0,"imagedir");
$fullpath=$gconfig['image-root']."/".$imagedir;

$name=mysql_result($result,0,"name");
$desc=mysql_result($result,0,"desc");
$siteid=mysql_result($result,0,"site_id");

?>

<html>
	<head>
		<?php echo "<title>$name</title>" ?>
		<meta http-equiv="content-type" content="text/html; charset=utf-8" />
		<meta name="description" content="<?php echo $desc ?>" />
		<meta name="keywords" content="<?php echo $sconfig['meta-keywords'] ?>" />
			
		<link rel="stylesheet" type="text/css" href="stylesheets/gallery.css" />
		
	</head>
	<body>  

	<table class="main-table"><tr><td width="125px" valign="top"></td><td>

<?php 
	$query="SELECT s.id, s.url, sb.banner_id, sb.code, sb.image
		FROM site_banner sb
		join site s on s.id = sb.site_id 
		where sb.banner_pos_id = 1
		and site_id = ".$siteid;
	$result=mysql_query($query);
	$num=mysql_numrows($result);
	
	if ($num == 0) {
		$query="SELECT s.id, s.url, sb.banner_id, sb.code, sb.image
		FROM site_banner sb
		join site s on s.id = sb.site_id 
		where sb.banner_pos_id = 1";
		$result=mysql_query($query);
		$num=mysql_numrows($result);
	}
	
	if ($num > 0) {
	
		$randint = rand(0, $num-1);
		
		$code=mysql_result($result,$randint,"code");
		if (!isset($code)) {
			$bannerimage = mysql_result($result,$randint,"image");
			$siteurl = mysql_result($result,$randint,"url");
			$code = '<a href="'.$siteurl.'"><img src="'.$bannerimage.'" alt="banner" /></a>';
		}
		
		echo $code;
		
	}
?>

</td><td></tr><tr><td>

</td>
<td class="main-td">

<div class="main-div">



<?php 

	include('title_bar.php');
	
	echo '<hr/>';
	
	echo '<h2>'.$name.'</h2>';
	echo '<h4>'.$desc.'</h4>';
	
	$files = scandir($fullpath);
	natsort($files);

	$settings = array('w'=>284,'h'=>300,'crop'=>true); 
	$i = 0;
	foreach ($files as &$file) {
		
		if (strncmp($file, ".", 1) != 0 && substr_count($file, ".jpg") > 0) {
			
			if ($siteid == 0 && $i == 0) {
				$i++;
				continue;
			}
			
			$imagepath = $fullpath."/".$file;
	   		$size = getimagesize($imagepath);
			
			echo '<a href="'.$imagepath.'">';

	   		echo '<div name="image-div" class="image-div ';
	    	if ($size[0] > $size[1]) {
	    		echo 'image-landscape';
	    	}
	    	else {
	    		echo 'image-portrait';
	    	}
	    	echo '">';
    	
	    	echo '<img src="'.resize($imagepath,$settings).'" alt="'.$name.' - '.$i.'"/>';	    	
	    	echo '</div>';
	    	echo "</a>";
	    	$i++;
		}
	}

?>

</div>
</td><td valign="top" width="125px">

<?php 

include("footer.php");

?>
